using JT808Protocol.Common;
using System;
using System.Text.Json.Serialization;

namespace JT808Protocol.Models.BodyParserStrategy.Location.LocationAddition
{
    /// <summary>
    /// 里程，DWORD，1/10km，对应车上里程表读数
    /// </summary>
    public class LaMileage_0x01 : ILocationAddition
    {
        /// <summary>
        /// 里程,0.1Km
        /// </summary>
        [JsonPropertyName("里程(0.1Km)")] public uint Mileage { get; set; }

        public override ILocationAddition ReadEntity(ReadOnlySpan<byte> source, int startIndex)
        {
            DataLength = (byte)(source[startIndex + 1] + 2);
            if (DataLength != 4 + 2)
            {
                //Logger.Warn($"位置附加信息的里程信息长度错误，略过解析");
                return null;
            }
            Mileage = ParseHelper.Uint32(ref source, startIndex + 2);

            return this;
        }
    }
}